package 回溯;

import java.util.ArrayList;
import java.util.List;

public class LeetCode17_电话号码的字母组合 {
    private String[] letterOnDigit = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    private List<String> pathList = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        if(digits == null || digits.length() == 0) {
            return pathList;
        }
        dfs(new StringBuilder(), digits);
        return pathList;
    }

    private void dfs(StringBuilder path, String digits) {
        if(path.length() == digits.length()) {
            pathList.add(path.toString());
            return;
        }
        int currentDight = digits.charAt(path.length()) - '0';
        String currentLetters = letterOnDigit[currentDight];
        for (char c : currentLetters.toCharArray()) {
            path.append(c);
            dfs(path, digits);
            path.deleteCharAt(path.length()-1);
        }
    }
}
